package com.roc.web.action.profit;

import java.util.ArrayList;
import java.util.List;

import com.roc.page.BaseSearchCondition;
import com.roc.page.WhereHQLFieldBean;
import com.roc.util.Constance;

public class ProfitDASumQuerySearchCondition extends BaseSearchCondition{

	private String beginTime;
	private String endTime;
	private long id;
	private long totalType;
	private String ids;
	protected String getOrderPartOfHQL() {
	/*	String groupBy ="";
		if(totalType==1){
			groupBy =" group by t.prod_cd, op.real_name, SUBSTR(t.create_date,0,6)";
		}else if(totalType==2){
			groupBy =" group by t.card_class, op.real_name, SUBSTR(t.create_date,0,6)";
		}else{
			 groupBy =" group by  t.prod_cd, t.card_class, op.real_name, SUBSTR(t.create_date,0,6)";
		}
*/
		
		// TODO Auto-generated method stub
		return "order by  op.account_no DESC ";
	}



	@Override
	protected String getRowCountHQL() {
		
		StringBuffer sb = new StringBuffer();
		sb.append("select count(1)  from ( ");
		if(totalType==1){
			sb.append("select op.real_name,sum(t.s_amt) s_amt,sum(t.merfee) merfee,sum(t.t_count) t_count ,SUBSTR(t.create_date,0,6) create_date ,t.prod_cd,op.account_no  from t_operators  op , t_profit_detail t where t.agent_id = op.id");
		}else if(totalType==2){
			sb.append("select  op.real_name,sum(t.s_amt) s_amt,sum(t.merfee) merfee,sum(t.t_count) t_count ,SUBSTR(t.create_date,0,6) create_date , t.card_class,op.account_no   from t_operators  op , t_profit_detail t where t.agent_id = op.id");
		}else{
			sb.append("select  op.real_name ,sum(t.s_amt) s_amt,sum(t.merfee) merfee,sum(t.t_count) t_count ,SUBSTR(t.create_date,0,6) create_date , t.card_class ,t.prod_cd ,op.account_no   from t_operators  op , t_profit_detail t where t.agent_id = op.id");
		}
		
		 if(Constance.isNotEmpty(beginTime)&&Constance.isNotEmpty(endTime)){
			 sb.append(" and t.create_date>='"+beginTime+"' and t.create_date<='"+endTime+"'");
	     }
		 if(-1==id){
			 sb.append(" and t.agent_id in "+ids);
	     }else{
	    	 sb.append(" and t.agent_id="+id);
	     }
		if(totalType==1){
			sb.append(" group by op.account_no ,t.prod_cd, op.real_name, SUBSTR(t.create_date,0,6)");
		}else if(totalType==2){
			sb.append(" group by op.account_no ,t.card_class, op.real_name, SUBSTR(t.create_date,0,6)");
		}else{
			sb.append(" group by op.account_no , t.prod_cd, t.card_class, op.real_name, SUBSTR(t.create_date,0,6)");
		}
		sb.append(")");
		return sb.toString();
	}


	protected String getSearchHQL() {
		StringBuffer sb = new StringBuffer();
		if(totalType==1){
			sb.append("select op.real_name,sum(t.s_amt) s_amt,sum(t.merfee) merfee,sum(t.t_count) t_count ,SUBSTR(t.create_date,0,6) create_date ,t.prod_cd,op.account_no   from t_operators  op , t_profit_detail t where t.agent_id = op.id");
		}else if(totalType==2){
			sb.append("select op.real_name,sum(t.s_amt) s_amt,sum(t.merfee) merfee,sum(t.t_count) t_count ,SUBSTR(t.create_date,0,6) create_date , t.card_class,op.account_no  from t_operators  op , t_profit_detail t where t.agent_id = op.id");
		}else{
			sb.append("select op.real_name ,sum(t.s_amt) s_amt,sum(t.merfee) merfee,sum(t.t_count) t_count ,SUBSTR(t.create_date,0,6) create_date , t.card_class ,t.prod_cd ,op.account_no  from t_operators  op , t_profit_detail t where t.agent_id = op.id");
		}
		
		 if(Constance.isNotEmpty(beginTime)&&Constance.isNotEmpty(endTime)){
			 sb.append(" and t.create_date>='"+beginTime+"' and t.create_date<='"+endTime+"'");
	     }
		 if(-1==id){
			 sb.append(" and t.agent_id in"+ids);
	     }else{
	    	 sb.append(" and t.agent_id="+id);
	     }
		if(totalType==1){
			sb.append(" group by op.account_no , t.prod_cd, op.real_name, SUBSTR(t.create_date,0,6)");
		}else if(totalType==2){
			sb.append(" group by op.account_no , t.card_class, op.real_name, SUBSTR(t.create_date,0,6)");
		}else{
			sb.append(" group by op.account_no , t.prod_cd, t.card_class, op.real_name, SUBSTR(t.create_date,0,6)");
		}

		return sb.toString();
	}

	
	@Override
	protected List<WhereHQLFieldBean> getWhereHQLFieldBeanList() {
		List<WhereHQLFieldBean> filedBeanList = new ArrayList<WhereHQLFieldBean>();

		/* if(Constance.isNotEmpty(beginTime)&&Constance.isNotEmpty(endTime)){
	        	filedBeanList.add(new WhereHQLFieldBean("t.create_date",beginTime,
						">=", false));
	        	filedBeanList.add(new WhereHQLFieldBean("t.create_date",endTime,
						"<=", false));
	     }
		 if(Constance.isNotEmpty(id)){
			if(!"99".equals(id)){
			 filedBeanList.add(new WhereHQLFieldBean("t.agent_id",id,"=", false));
			 
			}else{
				filedBeanList.add(new WhereHQLFieldBean("t.agentId",operators_array,
						"IN", false)); 
			 }
		 }*/
		return filedBeanList;
	}


	public String getBeginTime() {
		return beginTime;
	}


	public void setBeginTime(String beginTime) {
		this.beginTime = beginTime;
	}


	public String getEndTime() {
		return endTime;
	}


	public void setEndTime(String endTime) {
		this.endTime = endTime;
	}


	public long getId() {
		return id;
	}


	public void setId(long id) {
		this.id = id;
	}



	public long getTotalType() {
		return totalType;
	}



	public void setTotalType(long totalType) {
		this.totalType = totalType;
	}



	public String getIds() {
		return ids;
	}



	public void setIds(String ids) {
		this.ids = ids;
	}


}
